package com.weixin.paleituo.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.weixin.paleituo.R;

/**
 * Author yichao
 * Time  2017/12/11 15:44
 * Dest  我的item控件
 */

public class ItemReleaseHouseView extends LinearLayout {

    private LinearLayout mLinearLayout;
    private TextView mTvName, mTvDetai;
    private View mViewLine;
    private ImageView mIvMore;
    private TextView mTvContent;

    public ItemReleaseHouseView(Context context) {
        this(context, null);
    }

    public ItemReleaseHouseView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);

        mLinearLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.item_release_house_layout, this, true);
        mTvName = mLinearLayout.findViewById(R.id.tv_name_item_release_house_layout);
        mTvDetai = mLinearLayout.findViewById(R.id.tv_detail_item_release_house_layout);
        mViewLine = mLinearLayout.findViewById(R.id.view_line_item_release_house_layout);
        mTvContent= mLinearLayout.findViewById(R.id.tv_content_item_release_house_layout);
        mIvMore= mLinearLayout.findViewById(R.id.iv_more_item_release_house_layout);
        TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.ItemReleaseHouseView);

        String name = attributes.getString(R.styleable.ItemReleaseHouseView_item_name);
        if (name != null && !name.equals("")) {
            mTvName.setText(name);
        }
        String detais = attributes.getString(R.styleable.ItemReleaseHouseView_item_detais);
        if (detais != null && !detais.equals("")) {
            mTvDetai.setText(detais);
        }
        String content = attributes.getString(R.styleable.ItemReleaseHouseView_item_content);
        if (content != null && !content.equals("")) {
            mTvContent.setText(content);
        }
        boolean isShowLine=attributes.getBoolean(R.styleable.ItemReleaseHouseView_item_showline,true);
        if (!isShowLine){
            mViewLine.setVisibility(INVISIBLE);
        }else {
            mViewLine.setVisibility(VISIBLE);

        }
        boolean isShowText=attributes.getBoolean(R.styleable.ItemReleaseHouseView_item_showtext,false);
        if (!isShowText){
            mTvDetai.setVisibility(INVISIBLE);
        }else {
            mTvDetai.setVisibility(VISIBLE);
        }
        boolean isShowIcon=attributes.getBoolean(R.styleable.ItemReleaseHouseView_item_showicon,false);
        if (!isShowIcon){
            mIvMore.setVisibility(INVISIBLE);
        }else {
            mIvMore.setVisibility(VISIBLE);

        }
        boolean isEdit=attributes.getBoolean(R.styleable.ItemReleaseHouseView_item_isedit,false);
       /* if (!isEdit){
            mEtContent.setFocusable(false);
            mEtContent.setFocusableInTouchMode(false);
        }else {
            mEtContent.setFocusableInTouchMode(true);
            mEtContent.setFocusable(true);
            mEtContent.requestFocus();

        }*/

        attributes.recycle();

    }

    public ItemReleaseHouseView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

    }
}
